//
//  SearchTopView.m
//  StationManager
//
//  Created by 泽华伟业 on 17/3/18.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "SearchTopView.h"

@interface SearchTopView ()
//美食按钮
@property (nonatomic,strong) UIButton *foodButton;
//酒店按钮
@property (nonatomic,strong) UIButton *hotelButton;
//超市按钮
@property (nonatomic,strong) UIButton *supermarketButton;
//加油站按钮
@property (nonatomic,strong) UIButton *gasStationButton;

@end

@implementation SearchTopView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self.foodButton setTitle:@"美食" forState:UIControlStateNormal];
        [self.hotelButton setTitle:@"酒店" forState:UIControlStateNormal];
        [self.supermarketButton setTitle:@"超市" forState:UIControlStateNormal];
        [self.gasStationButton setTitle:@"加油站" forState:UIControlStateNormal];
    }
    return self;
}

- (UIButton *)foodButton{
    if (!_foodButton ) {
        _foodButton = [[UIButton alloc]init];
        [self addButtonAndSetStyle:_foodButton];
        [_foodButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.top.bottom.equalTo(self);
            make.width.equalTo(self).dividedBy(4);
        }];
    }
    return _foodButton;
}

- (UIButton *)hotelButton{
    if (!_hotelButton) {
        _hotelButton = [[UIButton alloc]init];
        [self addButtonAndSetStyle:_hotelButton];
        [_hotelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.top.bottom.equalTo(_foodButton);
            make.left.equalTo(_foodButton.mas_right);
        }];
    }
    return _hotelButton;
}

- (UIButton *)supermarketButton{
    if (!_supermarketButton) {
        _supermarketButton = [[UIButton alloc]init];
        [self addButtonAndSetStyle: _supermarketButton];
        [_supermarketButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_hotelButton.mas_right);
            make.size.top.bottom.equalTo(_hotelButton);
        }];
    }
    return _supermarketButton;
}

- (UIButton *)gasStationButton{
    if (!_gasStationButton) {
        _gasStationButton = [[UIButton alloc]init];
        [self addButtonAndSetStyle:_gasStationButton];
        [_gasStationButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_supermarketButton.mas_right);
            make.size.top.bottom.equalTo(_supermarketButton);
        }];
    }
    return _gasStationButton;
}

- (void)addButtonAndSetStyle:(UIButton *)button{
    [self addSubview:button];
    [button.titleLabel setFont:TEXT_FONT];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIView *lineView = [[UIView alloc]init];
    [button addSubview:lineView];
    lineView.backgroundColor = [UIColor lightGrayColor];
    //添加点击方法
    [button addTarget:self action:@selector(buttonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button).offset(3);
        make.bottom.equalTo(button.mas_bottom).offset(-3);
        make.left.equalTo(button.mas_right);
        make.width.mas_equalTo(1);
    }];
}

#pragma mark -- 按钮点击方法
- (void)buttonDidSelected:(UIButton *)sender{
    //将button的标题传出去
    self.buttonTitleBlock(sender.titleLabel.text);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
